<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
class Parser_Tag_code extends Parser {
	public $tags_inside = false;
	public $allowBr = false;
	
	private function code($source){
		 $source = str_replace( '\\'        , '&#92;' , $source );
		 $source = str_replace( '<'         , '&#60;' , $source );
		 $source = str_replace( '>'         , '&#62;' , $source );
		 $source = str_replace( '`'		   , '&#96;' , $source );
		 $source = str_replace( '&lt;'      , '&#60;' , $source );
		 $source = str_replace( '\''        , '&#39;' , $source );
		 $source = str_replace( '&quot;'    , '&#34;' , $source );
		 $source = str_replace( '"'     	   , '&#34;' , $source );
		 $source = str_replace( ':'         , '&#58;' , $source );
		 $source = str_replace( ')'         , '&#41;' , $source );
		 $source = str_replace( '('         , '&#40;' , $source );
		 $source = str_replace( '/'         , '&#47;' , $source );
		 $source = str_replace( '{'         , '&#123;', $source );
		 $source = str_replace( '}'         , '&#125;', $source );
		 $source = str_replace( '['         , '&#91;' , $source );
		 $source = str_replace( ']'         , '&#93;' , $source );
		 $source = str_replace( '='         , '&#61;' , $source );
		 $source = str_replace( chr(9)      , '&nbsp;&nbsp;&nbsp;&nbsp;', $source );
		 return $source;
	}

	public function get($inner,$param = ''){
		return '<pre class="code">'.$this->code($inner).'</pre>';
	}
	public function unparse($code){
		return preg_replace('~\<pre class=\"code\">(.*?)<\/pre>~is','[code]$1[/code]',$code);
	}
}